﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Xml;

namespace UpdateSearchConsole
{
	class Program
	{
		static void Main(string[] args)
		{
			string XMLSearchIndexPath = ConfigurationSettings.AppSettings["XMLSearchIndex"].ToString();
			XmlDocument xDocument = new XmlDocument();
			xDocument.Load(XMLSearchIndexPath);

			foreach (XmlNode xSearch in xDocument.DocumentElement.ChildNodes)
			{
				using (Process p1 = new Process())
				{
					p1.StartInfo.FileName = ConfigurationSettings.AppSettings["SVNPath"].ToString();
					p1.StartInfo.UseShellExecute = false;
					p1.StartInfo.CreateNoWindow = true;
					p1.StartInfo.WorkingDirectory = xSearch.Attributes["FileSystemPathRoot"].Value.ToString();
					p1.StartInfo.Arguments = "update --force --non-interactive --quiet --no-auth-cache " + xSearch.Attributes["FileSystemPathRoot"].Value.ToString();
					p1.Start();
					p1.WaitForExit();
				}
				using (Process p2 = new Process())
				{
					p2.StartInfo.FileName = ConfigurationSettings.AppSettings["SWISHEPath"].ToString();
					p2.StartInfo.UseShellExecute = false;
					p2.StartInfo.CreateNoWindow = true;
					p2.StartInfo.WorkingDirectory = xSearch.Attributes["SwishESearchWorkingDir"].Value.ToString();
					p2.StartInfo.Arguments = "-c index.config";
					p2.Start();
					p2.WaitForExit();
				}
			}
		}
	}
}
